﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DCTLib.Common;
using System.Data;

namespace DCTAccess.Business.Property
{
    public class MemTransaction
    {
        public static DataTable GetAllTransaction(int id)
        {
            SQLHelper sqlHelper = new SQLHelper();
            string sProc = "Transaction_GetAll";
            sqlHelper.AddParameter("@id", id);
            return sqlHelper.GetDataTable(sProc);
        }

        public static string SumOfUser(string uName)
        {
            string sql = string.Format("select MemberID from Web_Members where username='{0}'", uName);
            int userNum = 0;
            if (!string.IsNullOrEmpty(uName))
            {
                sql = string.Format(@"DECLARE @levelCode varchar(1000)
                SET @levelCode = cast((SELECT MemberID FROM Web_Members WHERE username ='{0}') AS varchar)+'|'
                SELECT count(*) FROM Web_Members 
                WHERE UniqueCode like '%'+@levelCode+'%'", uName);
                userNum = int.Parse(SQLHelper.TExecuteScalar(sql).ToString());
            }
            return StringHelper.StringConvertUserNum(userNum);
        }

        public static string PointOfUser(string uName)
        {
            decimal sumPoint = 0;
            string sql = string.Format(@"SELECT coalesce(sum(pointNumber), 0) AS pointNumber
            FROM [Property] WHERE MemberID=cast((SELECT MemberID FROM Web_Members WHERE username ='{0}') AS varchar)", uName);
            sumPoint = decimal.Parse(SQLHelper.TExecuteScalar(sql).ToString());
            return StringHelper.StringConvertPoint(sumPoint);
        }

        //public static string GetUniqueCode(string unique)
        //{
        //   string sql = string.Format(@"select UniqueCode from Members where uniquecode like '%@Unique%'",unique);
        //   return Convert.ToString(SQLHelper.TExecuteScalar(sql));
        //}
    }
}
